package sgi.client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;

import sgi.client.SGIPurchaseImageController.Source;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class SGIPurchaseSampleUI extends SGIClientFrame {

	private JPanel contentPane;
	private SGIPurchaseSampleController controller;

	public SGIPurchaseSampleUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 311, 146);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		setContentPane(contentPane);
		setLocationRelativeTo(null);
		
		JLabel lblAreYouSure = new JLabel("You are about to purchase a sample for this image.");
		lblAreYouSure.setBounds(10, 15, 275, 14);
		contentPane.add(lblAreYouSure);
		
		JLabel lblAreYouSure_1 = new JLabel("Are you sure ?");
		lblAreYouSure_1.setBounds(10, 35, 275, 14);
		contentPane.add(lblAreYouSure_1);
		
		JButton btnYes = new JButton("Yes");
		btnYes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				controller.purchase();			
				}
		});
		btnYes.setBounds(54, 63, 89, 23);
		contentPane.add(btnYes);
		
		JButton btnNo = new JButton("No");
		btnNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
					SGIPurchaseSampleController.terminate();
					if(controller.getSource() == Source.search)
						try {
							SGISearchArchiveController.create();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					else
						try {
							SGIInteractiveMapController.create();
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}

				}
		});
		btnNo.setBounds(151, 63, 89, 23);
		contentPane.add(btnNo);
	}

	public SGIPurchaseSampleController getController() {
		return controller;
	}

	public void setController(SGIPurchaseSampleController controller) {
		this.controller = controller;
	}
}
